#include "userinfowidget.h"

UserInfoWidget::UserInfoWidget(const UserInfo &userInfo, QWidget *parent)
    :QDialog(parent), _userInfo(userInfo)
{
    // 设置窗口属性
    this->setFixedSize(400, 200);
    this->setWindowTitle("用户信息");
    this->setWindowIcon(QIcon(":/resource/image/logo.png"));
    this->setAttribute(Qt::WA_DeleteOnClose);
    this->move(QCursor::pos());

    // 创建网格布局管理器
    QGridLayout *layout = new QGridLayout();
    layout->setVerticalSpacing(10);
    layout->setHorizontalSpacing(20);
    layout->setContentsMargins(50, 20, 0, 0);
    layout->setAlignment(Qt::AlignTop);
    this->setLayout(layout);

    QString labelStyle = "QLabel { font-size: 14px; font-weight: 600; }";
    QString btnStyle = "QPushButton { border: 1px solid rgb(100, 100, 100); background-color: rgb(240, 240, 240); }";
    btnStyle += "QPushButton:pressed { background-color: rgb(210, 210, 210); }";
    int width = 120;
    int height = 30;

    // 添加头像
    _avatarBtn = new QPushButton();
    _avatarBtn->setFixedSize(75, 75);
    _avatarBtn->setIconSize(QSize(75, 75));
    _avatarBtn->setIcon(_userInfo._avatar);
    _avatarBtn->setStyleSheet("QPushButton { border: none; background-color: transparent; }");

    // 添加用户信号
    _idTag = new QLabel();
    _idTag->setFixedSize(width, height);
    _idTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    _idTag->setText("序号");
    _idTag->setStyleSheet(labelStyle);

    _idLabel = new QLabel();
    _idLabel->setText(_userInfo._user_id);
    _idLabel->setFixedSize(width, height);
    _idLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    // 添加用户昵称
    _nameTag = new QLabel();
    _nameTag->setFixedSize(width, height);
    _nameTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    _nameTag->setText("昵称");
    _nameTag->setStyleSheet(labelStyle);

    _nameLabel = new QLabel();
    _nameLabel->setText(_userInfo._nickname);
    _nameLabel->setFixedSize(width, height);
    _nameLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    // 添加邮箱
    _mailTag = new QLabel();
    _mailTag->setFixedSize(width, height);
    _mailTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    _mailTag->setText("邮箱");
    _mailTag->setStyleSheet(labelStyle);

    _mailLabel = new QLabel();
    _mailLabel->setText(_userInfo._mail);
    _mailLabel->setFixedSize(width, height);
    _mailLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    // 添加功能按钮
    _applyBtn = new QPushButton();
    _applyBtn->setFixedSize(80, 30);
    _applyBtn->setStyleSheet(btnStyle);
    _applyBtn->setText("添加好友");
    _applyBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    _sendMsgBtn = new QPushButton();
    _sendMsgBtn->setFixedSize(80, 30);
    _sendMsgBtn->setStyleSheet(btnStyle);
    _sendMsgBtn->setText("发送消息");
    _sendMsgBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    _deleteBtn = new QPushButton();
    _deleteBtn->setFixedSize(80, 30);
    _deleteBtn->setStyleSheet(btnStyle);
    _deleteBtn->setText("删除好友");
    _deleteBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    // 添加到布局管理器中
    layout->addWidget(_avatarBtn, 0, 0, 3, 1);

    layout->addWidget(_idTag, 0, 1);
    layout->addWidget(_idLabel, 0, 2);

    layout->addWidget(_nameTag, 1, 1);
    layout->addWidget(_nameLabel, 1, 2);

    layout->addWidget(_mailTag, 2, 1);
    layout->addWidget(_mailLabel, 2, 2);

    layout->addWidget(_applyBtn, 3, 0);
    layout->addWidget(_sendMsgBtn, 3, 1);
    layout->addWidget(_deleteBtn, 3, 2);
}
